package com.ft.turorial.spring.boot.security.oauth2.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Options.FlushCachePolicy;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ft.turorial.spring.boot.security.oauth2.domain.OAuth2Client;

@Mapper
public interface OAuth2ClientMapper {
	@Insert("insert into oauth2_client (client_name, client_id, client_secret)"
	    	+ "values (#{clientName,jdbcType=VARCHAR}, #{clientId,jdbcType=VARCHAR}, #{clientSecret,jdbcType=VARCHAR})")
	@Options(keyProperty="id",useGeneratedKeys=true,flushCache=FlushCachePolicy.FALSE,timeout=10000)
	public OAuth2Client createOauth2Client(OAuth2Client oAuth2Client);
	@Update("update oauth2_client set client_name=#{clientName,jdbcType=VARCHAR}, "
			+ "client_id=#{clientId,jdbcType=VARCHAR}, client_secret=#{clientSecret,jdbcType=VARCHAR} "
			+ "where id = #{id,jdbcType=INTEGER}")
    public OAuth2Client updateOauth2Client(OAuth2Client oAuth2Client);
	@Delete("delete from oauth2_client where id = #{id,jdbcType=INTEGER}")
    public void deleteOauth2Client(Long id);
	
    OAuth2Client findOne(Long clientId);

    List<OAuth2Client> findAll();

    @Select("select * from oauth2_client where client_id=#{clientId,jdbcType=VARCHAR}")
    OAuth2Client findByOauth2ClientId(String clientId);
    @Select("select * from oauth2_client where client_secret=#{clientSecret,jdbcType=VARCHAR}")
    OAuth2Client findByOauth2ClientSecret(String clientSecret);
}
